import numpy as np
import matplotlib.pyplot as plt
from sklearn.linear_model import LogisticRegression
from sklearn.model_selection import train_test_split
from sklearn.metrics import accuracy_score

def sigmoid(z):
    return 1 / (1 + np.exp(-z))

def main():
    # 数据准备
    X = np.array([
        [0, 0, 0, 0, 0, 0],  
        [1, 0, 1, 0, 0, 0],  
        [1, 0, 0, 0, 0, 0],  
        [0, 0, 1, 0, 0, 0],  
        [2, 0, 0, 0, 0, 0],  
        [0, 1, 0, 0, 1, 1],  
        [1, 1, 0, 1, 1, 1],  
        [1, 1, 0, 0, 1, 0],  
        [1, 1, 1, 1, 1, 0],  
        [0, 2, 2, 0, 2, 1],  
        [2, 2, 2, 2, 2, 0],  
        [2, 0, 0, 2, 2, 1],  
        [0, 1, 0, 1, 0, 0],  
        [2, 1, 1, 1, 0, 0],  
        [1, 1, 0, 0, 1, 1],  
        [2, 0, 0, 2, 2, 0],  
        [0, 0, 1, 1, 1, 0]   
    ])
    y = np.array([1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0])
    feature_names = ['色泽', '根蒂', '敲声', '纹理', '脐部', '触感']
    X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)

    # 训练逻辑回归模型
    model = LogisticRegression()
    model.fit(X_train, y_train)

    # 预测
    y_pred = model.predict(X_test)

    # 评估模型
    accuracy = accuracy_score(y_test, y_pred)
    print(f"模型准确率: {accuracy}")

if __name__ == "__main__":
    main()